package org.jeecg.access.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.access.constant.PlatformType;
import org.jeecg.access.entity.AccountData;
import org.jeecg.access.entity.PlatformTotal;
import org.jeecg.access.entity.WorkData;
import org.jeecg.access.platform.mapper.DyCountMapper;
import org.jeecg.access.service.UnifiedPlatformService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @description: 抖音数据统计服务实现
 * @author: taogang
 * @date: 2025/7/23 9:14
 */
@Slf4j
@Service
public class DyCountDataServiceImpl extends AbstractCountDataService implements UnifiedPlatformService {
    private final DyCountMapper dyCountMapper;

    public DyCountDataServiceImpl(DyCountMapper dyCountMapper) {
        this.dyCountMapper = dyCountMapper;
    }

    @Override
    protected List<AccountData> queryAccountData() {
        try {
            return dyCountMapper.getDataList();
        } catch (Exception e) {
            log.error("获取平台明细数据失败", e);
            return new ArrayList<>();
        }
    }

    @Override
    protected List<WorkData> queryWorksData() {
        try {
            return dyCountMapper.getWorksList();
        } catch (Exception e) {
            log.error("获取作品列表数据失败", e);
            return new ArrayList<>();
        }
    }

    @Override
    public PlatformTotal getAccountTotal() {
        PlatformTotal platformTotal = new PlatformTotal();
        try {
            PlatformTotal result = dyCountMapper.getAccountNum();
            if (result != null) {
                platformTotal = result;
            }
            platformTotal.setPlatformSign(PlatformType.DY.getCode());
            platformTotal.setReadCount(0);
        } catch (Exception e) {
            log.error("获取抖音账号统计数据失败", e);
        }
        return platformTotal;
    }

    @Override
    public AccountData getPlatformTotal() {
        AccountData result = new AccountData();
        try {
            AccountData data = dyCountMapper.getPlatformTotal();
            if (data != null) {
                result = data;
            }
        } catch (Exception e) {
            log.error("获取平台总计数据失败", e);
        }
        return result;
    }

    @Override
    public String getPlatformTypeCode() {
        return PlatformType.DY.getCode();
    }
}